package main

import (
	"fmt"
	"strconv"
)

func countAndSay(n int) string {
	//初始值当成是字符串，有助于遍历
	s := "1"
	if n < 0 {
		return ""
	}

	if n == 1 {
		return s
	}

	for i := 1; i < n; i++ {
		prev := '.'
		count := 0
		output := ""
		for _, v := range s {
			if prev == v || prev == '.' {
				count++
			} else {
				output = output + strconv.Itoa(count) + string(prev)
				count = 1
			}

			prev = v
		}
		//fmt.Println(output, count, prev)

		output = output + strconv.Itoa(count) + string(prev)
		s = output

	}

	return s
}

func main() {
	fmt.Println(countAndSay(4))
}
